<?php
class AutoTimestampBehavior extends CActiveRecordBehavior {
 
  /**
   * The field that stores the modification time
   */
  public $created = 'registeredDate';
  public $modified = 'updatedDate';
 
  public function beforeValidate() {

    if ($this->Owner->isNewRecord) {
      $this->Owner->{$this->created} = date('Y-m-d H:i:s', time());
      $this->Owner->{$this->modified} = date('Y-m-d H:i:s', 0);
    } else {
      $this->Owner->{$this->modified} = date('Y-m-d H:i:s', time());
    }

    return true;    
  }

}
